package com.smartcruise.task.taskSearch;

import android.text.TextUtils;

import com.smartcruise.data.cruiseData.CruiseData;
import com.smartcruise.task.TaskAdapter;
import com.smartcruise.util.Key;
import com.smartcruise.util.TempleUser;

import io.realm.RealmResults;

/**
 * Created by FengChaoQun
 * on 2018/1/21 0021
 */

public class SearchPresenterImp implements SearchContract.Presenter {

    private SearchContract.View mView;

    public SearchPresenterImp(SearchContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void start() {
    }

    @Override
    public void search(String searchKey) {
        if (TextUtils.isEmpty(searchKey)) {
            return;
        }
        RealmResults<CruiseData> all = mView.getRealm().where(CruiseData.class)
                .equalTo(Key.inspectorId, TempleUser.getInstance().getAccount())
                .beginGroup()
                .contains(Key.name, searchKey)
                .or()
                .contains(Key.type, searchKey)
                .endGroup()
                .findAll();
        TaskAdapter taskAdapter = new TaskAdapter(mView.getActivity(), all);
        mView.showSearchResult(taskAdapter);
    }
}
